const Router = require('koa-router')
const { userValidator,verifyUser,crpytPassword,verifyLogin } = require('../middleware/user.middleware')
const { auth,getInfoAuth } = require('../middleware/auth.middleware')
const { register, login,info ,changePassword} = require('../controller/user.controller')

const router = new Router({ prefix: '/users' })

// 注册接口
router.post('/register',userValidator,verifyUser,crpytPassword, register)

// 登录接口
router.post('/login',userValidator, verifyLogin,login)

// 获取用户信息
router.get('/info',getInfoAuth,info)


// 用户退出
router.post('/logout',(ctx,next)=>{
    ctx.body = {
        code: 0,
        data: 'success'
    }
})



// 修改
router.patch('/',auth,crpytPassword,changePassword)
module.exports = router